﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mafserver.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Heritage.Codebox" %>
<%@ Import Namespace="Heritage.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    var inprogress = false;
    function ReadMessage(id) {
        if (inprogress) return;
        inprogress = true;
            $.ajax({
            type: "GET",
            url: "/Social/MarkAsRead",
            data: "id="+id,
            success: function (html) {
                var elem = document.getElementById(id);
                if (elem.style.display == "none") elem.style.display = "";
                else elem.style.display = "none";
                inprogress = false;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var elem = document.getElementById(id);
                if (elem.style.display == "none") elem.style.display = "";
                else elem.style.display = "none";
                inprogress = false;
            }
        });

    }
</script>
<%
    var lmdl = ViewData.Model as List<SocialMessageModel>; %>
<div class="mainname" style="margin-bottom:10px;">
    <div style="float:left;padding-top:12px;"><span class="FreeSetBold" style=" padding-left: 30px; padding-bottom: 0px; margin-top:0px; color:#0E1A21;font-size:20px;">Личные сообщения</span></div>
    </div>
    <div class="lowercontent" style="color:#6B562D; font-size:12px;">
    <% if (Utils.IsGameMasterAndAbove())
       {%>
    <div style="font-size:xx-small; font-style:bold; padding-bottom:4px; margin-bottom:6px;border-bottom:1px solid #EFE7D8"><a href="/Social/WriteMessage">Новое сообщение</a></div>
    <%
       }
       if (lmdl.Count == 0)
       {%>
    Нет сообщений
    <%
        }
       else
       {%>
       Страницы:<br /> 
       <%for (int i = 0; i < (int)ViewData["AllPages"]; i++)
{%>
       <a class="myhref2" style="font-size:11px; font-weight:bold;" href="/Social/Mail/<%=(i + 1)%>">[<%=(i + 1)%>]</a>&nbsp;
       <%
}%>
    <br /><br /><table cellspacing=0 cellpadding=5>
    <%
           foreach (var model in lmdl)
           {%>
    <tr<%=(!model.IsRead ? " style=\"background-color:#fdd;\"" : "")%>>
    <td class="sociallist"><img src="<%=Utils.GetSocialIcon(model.MessageType) %>" width="32px" height="32px" /></td>
    <td class="sociallist" style="white-space:nowrap;font-weight:bold;">
    <%if (model.FromGuid != Guid.Empty)
{%>
    <a href="/Home/Personal/<%=model.FromGuid%>" class="myhref2"><%=model.FromName%></a>
    <%
} else
{%>
    <%=model.FromName%>
<%}%>
    </td>
    <td class="sociallist"style="white-space:nowrap;font-weight:bold;font-size:10px;"><%=model.MessageDate.ToString("dd.MM.yy<br>HH:mm:ss")%></td>
    <td width="100%" class="sociallist"><a href="#" class="myhref2" style="font-weight:bold;" onclick="ReadMessage('<%=model.MessageID%>');return false;"><%=model.MessageSubject%></a></td>    
    <td class="sociallist"><a href="/Social/DeleteMessage/<%=ViewData["Page"]%>/<%=model.MessageID%>"><img src="/Images/Icons/Xion.png"/></a></td>
    </tr>
    <tr<%=(!model.IsRead
                                      ? " style=\"background-color:#fdd;display:none;\""
                                      : " style=\"display:none;\"")%> id="<%=model.MessageID%>"><td class="sociallist_b" colspan="3"></td><td class="sociallist_b" style="border-top:1px dashed #D1BC92" colspan="2"><%=model.MessageBody%>
                                      <% if (model.FromGuid != Guid.Empty && (model.MessageType == Constants.SOCIALMESSAGE_TYPE_PRIVATE || Utils.IsGameMasterAndAbove())) {%>
                                        <br /><br /><a href="/Social/ReplyMail/<%=model.MessageID %>/<%=ViewData["Page"] %>">Ответить</a>
                                      <%
                                        }%>
                                      </td></tr>
    <%
           }%>
      <tr><td colspan="5" class="sociallist"></td></tr>
    </table>
    <%
       }%>
   </div>
</asp:Content>
